package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.TravelContent;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.query.TravelQuery;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/travel")
public class TravelController {
    @Reference
    private ITravelService travelService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") TravelQuery qo, Model model) {
        model.addAttribute("pageInfo",travelService.query(qo));
        return "travel/list";
    }

    @ResponseBody
    @RequestMapping("/getTravelContent")
    public Object getTravelContent(Long id){

        TravelContent travelContent = travelService.getTravelContent(id);
        return travelContent;
    }

    @ResponseBody
    @RequestMapping("/updateState")
    public Object updateState(Long id, Integer state) {
        AjaxResult result = new AjaxResult();
        try {
            travelService.updateState(id, state);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("操作失败");
        }
        return result;
    }
}
